package cn.tedu.mall.book.controller;


import cn.tedu.mall.book.pojo.dto.BannerAddNewDTO;
import cn.tedu.mall.book.pojo.vo.BannerSimpleVO;
import cn.tedu.mall.book.service.IBannerService;
import cn.tedu.mall.book.web.JsonResult;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "轮播图管理")
@RequestMapping(value = "/banners", produces = "application/json;charset=utf-8")
public class BannerController {
    @Autowired
    IBannerService service;
    @PostMapping("/add")
    public JsonResult add(@RequestBody BannerAddNewDTO bannerAddNewDTO){
        service.addNew(bannerAddNewDTO);
        return JsonResult.ok();
    }

    @GetMapping("/delete/{id}")
    public JsonResult delete(@PathVariable Integer id){
        service.deleteById(id);
        return JsonResult.ok();
    }

    @GetMapping("/getBanner")
    public JsonResult<List<BannerSimpleVO>> getBanner() {
        return JsonResult.ok(service.getBanner());
    }
}
